from sqlalchemy import Column, String, create_engine, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

# 创建对象的基类:
Base = declarative_base()


# 定义User对象:
class video_list(Base):
    # 表的名字:
    __tablename__ = 'video_list'

    # 表的结构:
    bvid = Column(String(20), primary_key=True)
    typeid = Column(Integer)
    author = Column(String(20))
    mid = Column(Integer)
    created = Column(Integer)
    length = Column(String(20))
    title = Column(String(100))
    is_union_video = Column(Integer)


class video_d(Base):
    # 表的名字:
    __tablename__ = 'video_d'

    # 表的结构:
    bvid = Column(String(20), primary_key=True)
    down_time = Column(Integer)
    state = Column(Integer)
    reply = Column(Integer)
    view = Column(Integer)
    danmaku = Column(Integer)
    favorite = Column(Integer)
    coin = Column(Integer)
    share = Column(Integer)
    now_rank = Column(Integer)
    his_rank = Column(Integer)
    evaluation = Column(Integer)


# 初始化数据库连接:
engine = create_engine("mysql+pymysql://root:Aa380562113.@192.168.2.8:3306/bilibili?charset=utf8")
# 创建DBSession类型:
DBSession = sessionmaker(bind=engine)

# 创建session对象:
session = DBSession()
# 创建新User对象:
new_user = User(id='5', name='Bob')
# 添加到session:
session.add(new_user)
# 提交即保存到数据库:
session.commit()
# 关闭session:
session.close()
